insert into  asm_morosi_poste 
 SELECT  S.SOG_ID,S.SOG_RAGSOC,E.PAR_ID,SCR_IMP_D,SCR_IMP_A,'A CREDITO' OCR,' ' descrizione--,x.t
               FROM V_SCRITTURADEST_EC E,SOGGETTO S,
               (SELECT CSI_IDCLI,PAR_ID,SUM(NVL(SCR_IMP_D,0))-SUM(NVL(SCR_IMP_A,0)) T
               FROM V_SCRITTURADEST_EC
               GROUP BY CSI_IDCLI,PAR_ID) x
               WHERE E.AZ_ID ='01' 
               and   E.CSI_IDCLI = S.CSI_ID
               and   s.az_id = '01'
               AND   E.STA_IDSYS_PARTITA = 15
               AND   E.DST_ID IN (5)
               AND   E.CSI_IDCLI=X.CSI_IDCLI
               AND   X.PAR_ID=E.PAR_ID
            and X.T <= 1
         -- and sog_id = 8851683
   order by sog_id,par_id